
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class GameOption {

	boolean HvH = true;
	boolean CvH = true;
	
    public GameOption() {
        final JFrame frame = new JFrame("Game Mode Option");

        // implement ItemListener interface
        class MyItemListener implements ItemListener {

            public void itemStateChanged(ItemEvent ev) {
                boolean selected = (ev.getStateChange() == ItemEvent.SELECTED);
                AbstractButton button = (AbstractButton) ev.getItemSelectable();
                String command = button.getActionCommand();
                if (selected) {
                    if (command.equals("HvH")) {
                        HvH = true;
                        CvH = false;
                    } else if (command.equals("CvH")) {
                        HvH = false;
                        CvH = true;
                    } else if (command.equals("CvC")) {
                        CvH = false;
                        HvH = false;
                    } 
                }
            }
        }
        class MyAction implements ActionListener{
        	  public void actionPerformed(ActionEvent e){
//        		  JOptionPane.showMessageDialog(frame,
//                          "HAVE FUN WITH THE GAME",
//                          "Message Dialog",
//                          -1);
        		  frame.setVisible(false);
        	  }
        	  }

        
        JRadioButton HvH = new JRadioButton("HUMAN vs HUMAN");
        HvH.setActionCommand("HvH");

        JRadioButton CvH = new JRadioButton("HUMAN vs COMPUTER");
        CvH.setActionCommand("CvH");

        JRadioButton CvC = new JRadioButton("COMPUTER vs COMPUTER");
        CvC.setActionCommand("CvC");

        JButton ok = new JButton("OK");
        ok.setActionCommand("OK");


        // add event handler
        MyItemListener myItemListener = new MyItemListener();
        HvH.addItemListener(myItemListener);
        CvH.addItemListener(myItemListener);
        CvC.addItemListener(myItemListener);
        
        MyAction myAction = new MyAction();
        ok.addActionListener(myAction);
        

        // add radio buttons to a ButtonGroup
        final ButtonGroup group = new ButtonGroup();
        group.add(HvH);
        group.add(CvH);
        group.add(CvC);
        group.add(ok);

        // Frame setting
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        Container cont = frame.getContentPane();

        cont.setLayout(new GridLayout(0, 1));
        cont.add(new JLabel("Please choose the message type:"));
        cont.add(HvH);
        cont.add(CvH);
        cont.add(CvC);
        cont.add(ok);

        frame.setVisible(true);
    }
    public boolean getHvH(){return HvH;}
    public boolean getHvC(){return CvH;}
}